﻿// ExitCommand.cs is part of AGatherBot.
//
// AGatherBot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 3 as
// published by the Free Software Foundation.
//
// AGatherBot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public version 2 License for more details.
//
// You should have received a copy of the GNU General Public License
// along with AGatherBot. If not, see <http://www.gnu.org/licenses/>.

using AGatherBot;
using System;

namespace AGatherBot.Commands
{
    public class ExitCommand : ISharpCommand
    {
        public string CommandName
        {
            get
            {
                return ("Exit");
            }
        }

        public string Execute(object sender, string input)
        {
            // If the sender is not the console, disregard it.
            if (!(sender is string) || ((string)sender != Properties.Resources.Console))
            {
                return ("Received exit from untrusted source.");
            }

            // Validate user exit.
            Console.Write("Are you sure you want to exit? (y/n/c) [c]: ");
            String strChoice = Console.ReadLine();

            // If the user explicitly chose to exit, exit the program.
            if (strChoice.ToLower() == "y")
            {
                // Do you want to unload the addons before exiting? Y for yes, N for no, C for cancel [c]
                Environment.Exit(1);
            }

            return ("Exit canceled.");
        }

        public string Help(object sender, string input)
        {
            return (string.Empty);
        }
    }
}